package com.sport.facilities.booking.system.htmlchecker;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LoginResultChecker extends BasicChecker{
	private final String TAG = "LoginResultChecker";
	
	private final String loginPattern = "Invalid User No.";
	private final String pwdPattern = "Invalid Net Password";
	
	public boolean hasLogin(String response) throws Exception{
		super.hasError(response);
		Pattern patternLogin = Pattern.compile(loginPattern);
		Pattern patternPwd = Pattern.compile(pwdPattern);

		Matcher matcherPwd = patternPwd.matcher(response);		
		Matcher matcherLogin = patternLogin.matcher(response);
		
		if (matcherLogin.find()) {
			throw new Exception(loginPattern);
		}
		else if (matcherPwd.find()){
			throw new Exception(pwdPattern);			
		}
		else {
			return true;
		}
		

	}

}
/*
Login Fail Pattern
12-28 17:48:00.235: I/System.out(11112): <html>   <head>     <title>Sports Facilities Booking System</title>
12-28 17:48:00.235: I/System.out(11112):      <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
12-28 17:48:00.235: I/System.out(11112):      <meta http-equiv='Expires' content='0'>
12-28 17:48:00.235: I/System.out(11112):      <meta http-equiv='Cache-Control' content='no-cache'>
12-28 17:48:00.235: I/System.out(11112):      <meta http-equiv='Pragma' content='no-cache'>
12-28 17:48:00.235: I/System.out(11112):      <script language='JavaScript'>
12-28 17:48:00.235: I/System.out(11112):      <!--
12-28 17:48:00.235: I/System.out(11112):      function popupMsg(msg) { //v1.0
12-28 17:48:00.235: I/System.out(11112):         alert(msg);
12-28 17:48:00.235: I/System.out(11112):         this.location='/saosport/login.htm';
12-28 17:48:00.235: I/System.out(11112):      }
12-28 17:48:00.235: I/System.out(11112):      //-->
12-28 17:48:00.235: I/System.out(11112):     </script>
12-28 17:48:00.235: I/System.out(11112):    </head>   <body bgcolor='#FFFFFF' onLoad="popupMsg('Invalid User No.')"></body> </html>
 * */

/*
Login Success Pattern
12-28 17:49:44.185: I/System.out(11279): <html>   <head>     <title>Sports Facilities Booking System</title>
12-28 17:49:44.185: I/System.out(11279):      <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>
12-28 17:49:44.185: I/System.out(11279):      <meta http-equiv='Expires' content='0'>
12-28 17:49:44.185: I/System.out(11279):      <meta http-equiv='Cache-Control' content='no-cache'>
12-28 17:49:44.185: I/System.out(11279):      <meta http-equiv='Pragma' content='no-cache'>
12-28 17:49:44.190: I/System.out(11279):      <script type='text/javascript'>
12-28 17:49:44.190: I/System.out(11279):         function gomenu(msg) { //v1.0
12-28 17:49:44.190: I/System.out(11279):           document.mainform.action='/saosport/spmenu';   
12-28 17:49:44.190: I/System.out(11279):           document.mainform.target='_top'; 
12-28 17:49:44.190: I/System.out(11279):           document.mainform.method='post';
12-28 17:49:44.190: I/System.out(11279):           document.mainform.submit();
12-28 17:49:44.190: I/System.out(11279):         }
12-28 17:49:44.190: I/System.out(11279):      </script>
12-28 17:49:44.190: I/System.out(11279):    </head>   <body bgcolor='#FFFFFF' onLoad="gomenu('bbq')">
12-28 17:49:44.190: I/System.out(11279):      <form action='' method=post name=mainform >
12-28 17:49:44.190: I/System.out(11279):      </form>   </body></html>
 * */
